package com.qk.management.service.impl;

import com.qk.common.PageResult;
import com.qk.entity.Role;
import com.qk.management.mapper.RoleMapper;
import com.qk.management.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author kaoM1Jy
 * @date 2025/10/8 20:00
 * @description:
 */
@Service
@SuppressWarnings("all")
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<Role> getAll() {
        return roleMapper.selectAll();
    }

    @Override
    public void update(Role role) {
        role.setUpdateTime(LocalDateTime.now());
        roleMapper.update(role);
    }

    @Override
    public Role getByID(Integer id) {
       Role role=  roleMapper.getById(id);
       return role;

    }

    @Override
    public void addRole(Role role) {
        role.setCreateTime(LocalDateTime.now());
        role.setUpdateTime(LocalDateTime.now());
       roleMapper.insert(role);
    }

    @Override
    public void deleteByID(Integer id) {
        roleMapper.deleteByID(id);
    }

    @Override
    public PageResult<Role> page(String name, String label, Integer page, Integer pageSize) {
        Integer total = roleMapper.count(name,label);
        Integer offset = (page-1)*pageSize;
        List<Role> rows = roleMapper.selectByPage(name,label,offset,pageSize);
        return PageResult.<Role>builder().total(total).rows(rows).build();
    }
}

